﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using InControl;

namespace GameJam
{
    public class InputCtrl : MonoBehaviour
    {
        private List<InControl.InputDevice> using_device_list;
        // Use this for initialization
		

        void Start()
        {
            using_device_list = new List<InputDevice>();
            UIMgr.Instance.menuUI.localPosition = Vector3.zero;

        }


        private bool isHadPressedStart = false;
        // Update is called once per frame
        void Update()
        {
            if (!isHadPressedStart)
            {
                foreach (InputDevice deviece in InputManager.Devices)
                {
                    if(deviece.Action1.WasPressed)
                    {
                        isHadPressedStart = true;
                        UIMgr.Instance.menuUI.localPosition = new Vector3(-10000,-10000,0);
                        GameCtrl.Instance.FirstStartGame();
                        break;
                    }
                }
            }
            else
            {


                if (GameCtrl.Instance.isCanJoinPlayer && !GameCtrl.Instance.IsHadStartGame)
                {
                    foreach (InputDevice deviece in InputManager.Devices)
                    {
                        if (!using_device_list.Contains(deviece) && deviece.AnyButton)
                        {
                            using_device_list.Add(deviece);
                            GameCtrl.Instance.AddPlayer(deviece);
                        }
                    }
                }

                if (GameCtrl.Instance.IsGameOver)
                {
                    foreach (InputDevice deviece in InputManager.Devices)
                    {
                        if (using_device_list.Contains(deviece) && deviece.Action1.WasPressed)
                        {
                            GameCtrl.Instance.ReStartGame();
                        }
                    }
                }
            }
        }
    }
}